package org.dftproject.pgv.ui;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Properties;

import org.dftproject.genesis.core.collections.Collection;
import org.dftproject.genesis.ui.collections.ICollectionHandler;
import org.dftproject.genesis.ui.pages.IPageInput;
import org.dftproject.pgv.core.racp.PGVGedcom;
import org.dftproject.pgv.core.racp.Session;
import org.dftproject.pgv.core.racp.SessionManager;

public class PGVCollectionHandler implements ICollectionHandler {

	public String getPageId(Collection collection) {
		return PGVPage.ID;
	}

	public IPageInput getPageInput(Collection collection) {		
		Properties props = new Properties();
		try {
			props.load(new ByteArrayInputStream(collection.getData().getBytes()));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		Session session = SessionManager.getDefault().getSession(props.getProperty("url"), props.getProperty("username"), props.getProperty("password"));
		return new PGVPageInput(new PGVGedcom(session, props.getProperty("gedcomId"), collection.getName()));
	}

}
